package com.study.happystudy.tool;

import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;

import java.io.UnsupportedEncodingException;

@Component
public class MD5Tool {
    /**
     * 将字符串转为MD5
     *
     * @param s 待转换的字符
     * @return String(MD5形式)
     */
//    public String ToMD5(String s) {
//        try {
//            return DigestUtils.md5DigestAsHex(s.getBytes("utf-8"));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return null;
//        }
//    }

    public static String ToMD5(String s){
        try {
            return DigestUtils.md5DigestAsHex(s.getBytes("utf-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }
}
